<?php

namespace app\admin\controller\auth;

use app\admin\controller\AdminController;
use app\admin\service\auth\DeptService;
use app\admin\validate\auth\DeptValidate;
use think\response\Json;

/**
 * 部门控制器
 */
class Dept extends AdminController
{

    /**
     * 查看部门列表
     * @return Json
     */
    public function lists()
    {
        return $this->data(DeptService::getList());
    }

    /**
     * 添加部门
     * @return Json
     */
    public function add()
    {
        $params = (new DeptValidate())->post()->checkParam('add');
        $result = DeptService::add($params);
        if(true === $result) {
            return $this->success([], '添加成功');
        } else {
            return $this->error(DeptService::getError());
        }
    }

    /**
     * 编辑部门
     * @return Json
     */
    public function edit()
    {
        $params = (new DeptValidate())->post()->checkParam('edit');
        $result = DeptService::edit($params);
        if (true === $result) {
            return $this->success([],'编辑成功');
        } else {
            return $this->error(DeptService::getError());
        }
    }

    /**
     * 删除部门
     * @return Json
     */
    public function delete()
    {
        $params = (new DeptValidate())->delete()->checkParam('delete');
        $result = DeptService::delete($params);
        if (true === $result) {
            return $this->success([],'删除成功');
        } else {
            return $this->error(DeptService::getError());
        }
    }

    /**
     * 部门详情
     * @return Json
     */
    public function detail()
    {
        $params = (new DeptValidate())->checkParam('detail');
        $result = DeptService::detail($params);
        return $this->data($result);
    }

    /**
     * 获取部门
     * @return Json
     */
    public function all()
    {
        $result = DeptService::getAllData();
        return $this->data($result);
    }
}